const { Sequelize } = require('sequelize')

const sequelize = new Sequelize('web前端', 'root', '123456', {
    host: 'localhost',
    dialect: 'mysql',
    logging: false,
    dialectOptions: {
        charset: 'utf8mb4'
    }
})

// 测试数据库连接
async function testConnection() {
    try {
        await sequelize.authenticate()
        console.log('数据库连接成功。')
    } catch (error) {
        console.error('数据库连接失败:', error)
        process.exit(1) // 如果连接失败，终止程序
    }
}

testConnection()

module.exports = sequelize
